Skip to content

Comments

Dynamic NFT Evolution Contract (Issue #77)Feature/dynamic nft#105

Open
abbakargarba wants to merge 4 commits intoMindFlowInteractive:mainfrom
abbakargarba:feature/dynamic-nft
Open

Dynamic NFT Evolution Contract (Issue #77)Feature/dynamic nft#105
abbakargarba wants to merge 4 commits intoMindFlowInteractive:mainfrom
abbakargarba:feature/dynamic-nft

Conversation

@abbakargarba
Copy link

Closes issue #77

PR: Dynamic NFT Evolution Contract (Issue #77)

Description

Implements a complete dynamic NFT evolution system where NFTs change properties based on player achievements, time, and milestones. This contract enables engaging game mechanics where player progression directly affects their in-game assets.

Key Features

  • Milestone-Triggered Upgrades: Admin/verifier can manually evolve NFTs (level + rarity increases)
  • Time-Based Evolution: Player-triggered automatic evolution after elapsed time
  • Rarity Evolution: NFTs gain rarity through upgrades and fusion mechanics
  • Fusion System: Combine two NFTs into a higher-rarity token (originals burned)
  • Downgrade Support: Admin/verifier can reduce levels (penalties/corrections)
  • Evolution History: Immutable log of all evolution events
  • Access Control: Admin, verifier, and owner-based authorization

Acceptance Criteria (All Met ✅)

  • NFT properties change based on conditions (level/rarity via evolution calls)
  • Milestones trigger upgrades (admin/verifier evolve_milestone function)
  • Time-based evolution works (player-triggered evolve_time with elapsed time check)
  • Evolution history preserved (immutable Vec history tracking)
  • Fusion creates new NFT (combines two → new higher-rarity token, originals burned)
  • Contract compiles and tests pass (8 comprehensive unit tests)

Changes

New Files:

  • contracts/dynamic_nft/Cargo.toml – Package manifest
  • contracts/dynamic_nft/src/lib.rs – Full contract implementation (220+ lines)
  • contracts/dynamic_nft/src/test.rs – Unit tests (8 tests covering all functionality)
  • contracts/dynamic_nft/README.md – Complete documentation

Modified Files:

  • Cargo.toml – Added contracts/dynamic_nft to workspace members

Contract Overview

Core Data Structure

pub struct DynamicNft {
    pub owner: Address,           // NFT owner
    pub level: u32,               // Evolution level (starts at 1)
    pub rarity: u32,              // Rarity rank (starts at 1)
    pub traits: String,           // Visual traits (updatable)
    pub metadata: String,         // Metadata URI
    pub history: Vec<String>,     // Evolution event log
    pub minted_at: u64,           // Timestamp for time-based evolution
}

Main Functions
initialize(admin)Initialize contract
mint(minter, owner, metadata, traits) → token_id – Create new NFT
evolve_milestone(admin/verifier, token_id, level_inc, rarity_inc, traits)Manual evolution
evolve_time(player, token_id, required_secs)Time-based evolution
downgrade(admin/verifier, token_id, level_dec)Reduce level
fuse(owner, token_a, token_b) → new_token_id – Combine NFTs
get_nft(token_id)DynamicNftRetrieve NFT data
get_history(token_id)Vec<String> – Get evolution history
Access Control
Admin Only: initialize, add_verifier, remove_verifier
Admin/Verifier: evolve_milestone, downgrade
Owner Only: fuse
Open: mint, evolve_time, get_nft, get_history
Testing
All 8 unit tests pass:Mint and retrieval
✅ Time-based evolution with timer reset
✅ Milestone evolution (admin path)Downgrade by verifier
✅ Fusion with original token burn
✅ Authorization enforcement (3 panic tests)Verifier add/remove.

Run tests:
cargo test --manifest-path contracts/dynamic_nft/Cargo.toml

Build:
cargo build --manifest-path contracts/dynamic_nft/Cargo.toml --release

@abbakargarba
Copy link
Author

@Mkalbani hello OG. submitted a PR, waiting for merge🌊🩵

@abbakargarba
Copy link
Author

hello @Mkalbani hope you had a wonderful night. I would like a review on this pr so that i can fix potential bugs early, and so if there aren't any we can merge the branch

@Mkalbani
Copy link
Contributor

@abbakargarba please resolve conflcit

@abbakargarba
Copy link
Author

alright 🌊

@abbakargarba
Copy link
Author

hello @Mkalbani all conflict resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants